import Mock from 'mockjs'

// MockJS 配置
export const mockConfig = {
  // 设置全局延迟
  timeout: '200-800',
  
  // 是否启用 MockJS
  enabled: true,
  
  // 调试模式
  debug: true
}

// 初始化 MockJS
export function initMockJS() {
  if (!mockConfig.enabled) {
    console.log('MockJS 已禁用')
    return
  }

  // 设置全局配置
  Mock.setup({
    timeout: mockConfig.timeout
  })

  // 启用调试模式
  if (mockConfig.debug) {
    Mock._mocked = {}
    
    // 添加请求日志
    Mock.mock(/.*/, 'get', function(options) {
      console.log('🔍 MockJS 拦截到 GET 请求:', options.url)
      return {
        code: 200,
        message: '请求成功',
        data: Mock.Random.dataImage('300x300', 'Mock Data')
      }
    })

    Mock.mock(/.*/, 'post', function(options) {
      console.log('🔍 MockJS 拦截到 POST 请求:', options.url)
      return {
        code: 200,
        message: '请求成功',
        data: Mock.Random.dataImage('300x300', 'Mock Data')
      }
    })

    Mock.mock(/.*/, 'put', function(options) {
      console.log('🔍 MockJS 拦截到 PUT 请求:', options.url)
      return {
        code: 200,
        message: '请求成功',
        data: Mock.Random.dataImage('300x300', 'Mock Data')
      }
    })

    Mock.mock(/.*/, 'delete', function(options) {
      console.log('🔍 MockJS 拦截到 DELETE 请求:', options.url)
      return {
        code: 200,
        message: '请求成功',
        data: Mock.Random.dataImage('300x300', 'Mock Data')
      }
    })
  }

  console.log('🚀 MockJS 初始化完成')
}
